package database;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import databaseInterface.CatalogManageInterface;

public class CatalogManage implements CatalogManageInterface{


	Statement stmt;
	DatabaseConnection db= new DatabaseConnection();
	public  void connect (){        
         stmt =db.connect();
    }
    
	public void insert (String str){
    	 String insert ="insert into catalog  values ('"+str+"')";
         try {
			stmt.executeUpdate(insert);		
         } catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    
   }

    
	public void delete (String str){   	
    	String delete="delete from catalog  where catalog = '"+str+"'" ;
    	try {
			stmt.executeUpdate(delete);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	 
	public  ArrayList<String> query (){
    	String query = "select * from catalog ";
    	ArrayList<String> tlist = new ArrayList<String> ();
     	try {
			ResultSet rs= stmt.executeQuery(query);
			while(rs.next()){
	    		String str= rs.getString(1);
	    	    tlist.add(str);
	    	
	    	}   	
    	} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	return tlist;	
    }
	public boolean query(String c){
		return false;
	}
public void close(){
	db.close();
}
}
